package org.tinygroup.springmvc.handler;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.support.ApplicationObjectSupport;
import org.tinygroup.assembly.AssemblyService;
import org.tinygroup.assembly.DefaultAssemblyService;

/**
 * 
 * @author renhui
 *
 */
public class MethodInvokePreHandlerComposite extends ApplicationObjectSupport
		implements InitializingBean {

	private List<MethodInvokePreHandler> methodInvokePreHandlers;

	private AssemblyService<MethodInvokePreHandler> assemblyService = new DefaultAssemblyService<MethodInvokePreHandler>();
	
	public AssemblyService<MethodInvokePreHandler> getAssemblyService() {
		return assemblyService;
	}

	public void setAssemblyService(
			AssemblyService<MethodInvokePreHandler> assemblyService) {
		this.assemblyService = assemblyService;
	}


	public List<MethodInvokePreHandler> getMethodInvokePreHandlers() {
		return methodInvokePreHandlers;
	}
	
	public void afterPropertiesSet() throws Exception {
		assemblyService.setApplicationContext(getApplicationContext());
		List<MethodInvokePreHandler> preHandlers = assemblyService
				.findParticipants(MethodInvokePreHandler.class);
		if (preHandlers == null) {
			preHandlers = new ArrayList<MethodInvokePreHandler>();
		}
		this.methodInvokePreHandlers=preHandlers;
	}

}
